//
//  MyFirstViewController.m
//  A段项目
//
//  Created by dlios on 15/7/10.
//  Copyright (c) 2015年 dlios. All rights reserved.
//

#import "MyFirstViewController.h"
#import "BaseHeader.h"
#import "MyCollectionViewCell.h"
#import "fixViewController.h"
#import "OldCarViewController.h"
#import "MoneyViewController.h"
#import "QiangViewController.h"
#import "ShopViewController.h"
#import "CViewController.h"



@interface MyFirstViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic, retain) UICollectionView *collect;
@property (nonatomic, retain) NSArray *nameArr;
@property (nonatomic, retain) NSArray *imageArr;

@end

@implementation MyFirstViewController

- (void)dealloc
{
    [_collect release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        
        self.nameArr = @[@"收藏",@"草稿箱",@"夜间模式",@"保养优惠",@"二手车",@"贷款购车",@"限时抢购",@"车商城"];
        self.imageArr = @[@"collect.png",@"write.png",@"moon.png",@"fix.png",@"oldcar.png",@"money.png",@"qiang.png",@"shop.png"];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"我的";
    
    
    
    UIImageView *titleview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeidth/3)];
    [titleview setImage:[UIImage imageNamed:@"back.jpg"]];
    [self.view addSubview:titleview];
    [self creatButton];
    // Do any additional setup after loading the view.
}

- (void)creatButton
{
//    UIButton *collect = [[UIButton alloc] initWithFrame:CGRectMake(0, ScreenHeidth/3+40, ScreenWidth/4, ScreenWidth/4)];
//    [collect setImage:[UIImage imageNamed:@"collect.png"] forState:UIControlStateNormal];
//    collect.layer.borderColor = [[UIColor colorWithRed:30/255.0 green:144/255.0 blue:1 alpha:1] CGColor];
//    [collect setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
//    collect.layer.cornerRadius = 9;
//    collect.layer.borderWidth = 2;
//    [self.view addSubview:collect];
//    
//    
//    UIButton *write = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth/4, ScreenHeidth/3+40, ScreenWidth/4, ScreenWidth/4)];
//    write.layer.borderColor = [[UIColor colorWithRed:30/255.0 green:144/255.0 blue:1 alpha:1] CGColor];    write.layer.borderWidth = 4;
//    write.layer.cornerRadius = 9;
//    write.layer.borderWidth = 2;
//    [self.view addSubview:write];
   
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing = 1;
    layout.minimumLineSpacing = 1;
    layout.itemSize = CGSizeMake(ScreenWidth/4-1, ScreenWidth/4);
    
    self.collect = [[UICollectionView alloc] initWithFrame:CGRectMake(0, ScreenHeidth/3, ScreenWidth, ScreenHeidth) collectionViewLayout:layout];
    [self.view addSubview:self.collect];
    self.collect.dataSource = self;
    self.collect.delegate = self;
    self.collect.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:0.8];
    [self.collect registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    

}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 8;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    cell.namelabel.text = [self.nameArr objectAtIndex:indexPath.row];
    NSString *str = [self.imageArr objectAtIndex:indexPath.row];
    [cell.image setImage:[UIImage imageNamed:str]];
    return cell;
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    OldCarViewController *old = [[OldCarViewController alloc] init];

    
    MoneyViewController *money = [[MoneyViewController alloc] init];
    
    
    fixViewController *fix = [[fixViewController alloc] init];

    QiangViewController *qiang = [[QiangViewController alloc] init];
    
    ShopViewController *shop = [[ShopViewController alloc] init];
    CViewController *c = [[CViewController alloc] init];
    
    UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"提示" message:@"暂无草稿" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    switch (indexPath.row) {
            case 0:
            [self.navigationController pushViewController:c animated:YES];
            [c release];
            
            
            break;
            case 1:
            [view show];
            [view release];

            break;
            case 2:
            if ( self.view.window.alpha == 1) {
            self.view.window.alpha = 0.4;
            }else{
            self.view.window.alpha = 1;
            }

            break;
        case 3:
            [self.navigationController pushViewController:fix animated:YES];
            [fix release];
            break;
            case 4:
            [self.navigationController pushViewController:old animated:YES];
            [old release];
            break;
            case 5:
            [self.navigationController pushViewController:money animated:YES];
            [money release];
            break;
            case 6:
            [self.navigationController pushViewController:qiang animated:YES];
            [qiang release];
            break;
        case 7:
            [self.navigationController pushViewController:shop animated:YES];
            [shop release];
            break;
        default:
            break;
    }
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
